/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StripeTableHeader.java
 *
 * Created on 27/11/2011, 23:01:33
 */
package bgu.sonar.util.ui.tables;

import bgu.sonar.util.ui.models.AbstractTabularModel;
import java.awt.Color;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author bennyl
 */
public class StripeTableHeader extends javax.swing.JPanel implements TableCellRenderer {

    /**
     * Creates new form StripeTableHeader
     */
    public StripeTableHeader() {
        initComponents();
    }

    @Override
    public void setForeground(Color fg) {
        super.setForeground(fg); //To change body of generated methods, choose Tools | Templates.
        if (text != null) {
            text.setForeground(fg);
        }
    }

    @Override
    public Color getForeground() {
        if (text == null) {
            return super.getForeground();
        }
        return text.getForeground();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        text = new javax.swing.JLabel();

        setBackground(new java.awt.Color(215, 215, 215));
        setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 1, new java.awt.Color(153, 153, 153)));
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        text.setBackground(new java.awt.Color(102, 102, 102));
        text.setFont(new java.awt.Font("Consolas", 1, 11)); // NOI18N
        text.setForeground(new java.awt.Color(102, 102, 102));
        text.setText("jLabel1");
        add(text);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel text;
    // End of variables declaration//GEN-END:variables

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        text.setIcon(null);
        text.setText(value.toString());

        if (table.getModel() instanceof AbstractTabularModel) {
            AbstractTabularModel model = (AbstractTabularModel) table.getModel();
            Icon icon = model.getColumnIcon(column);
            if (icon != null) {
                text.setText("");
                text.setIcon(icon);
            }
        }
        return this;
    }
}
